package com.yisoo.ubag.iot.util;


import com.alibaba.fastjson.JSONArray;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;


public class MqttDataMapping {

    public static String getDataPack(Integer order){

        switch(order){
//            关于存储箱控制的问题
            case 101://开启存储箱的指令
                ControlDataPack dataPack101 = ControlDataPack.openBox();
                return JSONArray.toJSON(dataPack101).toString().replace("\"","");

            case 102://关闭存储箱的指令
                ControlDataPack dataPack102 = ControlDataPack.closeBox();
                return JSONArray.toJSON(dataPack102).toString().replace("\"","");
//            关于背包控制的问题
            case 201://开背包，亮紫灯
                ControlDataPack dataPack201 = ControlDataPack.openBag();
                return JSONArray.toJSON(dataPack201).toString().replace("\"","");
            case 202://关背包，关紫灯
                ControlDataPack dataPack202 = ControlDataPack.closeBag();
                return JSONArray.toJSON(dataPack202).toString().replace("\"","");
            case 203://开无线充电
                ControlDataPack dataPack203 = ControlDataPack.openNBao();
                return JSONArray.toJSON(dataPack203).toString().replace("\"","");
            case 204://关无线充电
                ControlDataPack dataPack204 = ControlDataPack.closeNBao();
                return JSONArray.toJSON(dataPack204).toString().replace("\"","");
            case 205://开无线充电
                ControlDataPack dataPack205 = ControlDataPack.openTran();
                return JSONArray.toJSON(dataPack205).toString().replace("\"","");
            case 206://关无线充电
                ControlDataPack dataPack206 = ControlDataPack.closeTran();
                return JSONArray.toJSON(dataPack206).toString().replace("\"","");
//            背包状态数据包
            case 301://背包状态数据上传打开
                ControlDataPack dataPack301 = ControlDataPack.openNbiot();
                return JSONArray.toJSON(dataPack301).toString().replace("\"","");
            case 302://背包状态数据上传关闭
                ControlDataPack dataPack302 = ControlDataPack.closeNbiot();
                return JSONArray.toJSON(dataPack302).toString().replace("\"","");
            default:
                return "{\"error\":1}";
        }
    }


    @AllArgsConstructor
    @NoArgsConstructor
    @Data
    @ToString
    static class ControlDataPack{//纯控制指令
        //关闭和开启存储箱的指令
        Integer cd;
        static ControlDataPack openBox(){
            return new ControlDataPack(101);
        }
        static ControlDataPack closeBox(){
            return new ControlDataPack(102);
        }

        static ControlDataPack openBag(){
            return new ControlDataPack(201);
        }
        static ControlDataPack closeBag(){
            return new ControlDataPack(202);
        }

        static ControlDataPack openNbiot(){
            return new ControlDataPack(301);
        }
        static ControlDataPack closeNbiot(){
            return new ControlDataPack(302);
        }

        static ControlDataPack openNBao(){
            return new ControlDataPack(203);
        }
        static ControlDataPack closeNBao(){
            return new ControlDataPack(204);
        }

        static ControlDataPack openTran(){
            return new ControlDataPack(205);
        }
        static ControlDataPack closeTran(){
            return new ControlDataPack(206);
        }

    }
    @AllArgsConstructor
    @NoArgsConstructor
    @Data
    @ToString
    static class ControlAndDataPack{//控制+数据指令
        Integer cd;//code
        String mg;//msg
    }
}

